package com.lzh.persevere.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lzh.persevere.common.R;
import com.lzh.persevere.common.ResultUtil;
import com.lzh.persevere.model.entity.Photo;
import com.lzh.persevere.model.entity.PhotoTag;
import com.lzh.persevere.model.qo.TagIdQO;
import com.lzh.persevere.model.ro.photo.AddPhotoRO;
import com.lzh.persevere.service.PhotoService;
import com.lzh.persevere.service.PhotoTagService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 照片controller
 *
 * @author luzhiheng
 * @since 2025-07-05
 */
@RestController
@RequestMapping("/photo")
public class PhotoController {

    @Resource
    private PhotoService photoService;

    @Resource
    private PhotoTagService photoTagService;

    @ApiOperation(value = "根据标签ID查询照片列表")
    @PostMapping("/findListByTagId")
    public R<List<Photo>> findListByTagId(@RequestBody @Valid TagIdQO qo) {
        List<Photo> photoList = photoService.list(Wrappers.<Photo>lambdaQuery().eq(Photo::getTagId, qo.getTagId()));
        return ResultUtil.success(photoList);
    }

    @ApiOperation(value = "添加照片")
    @PostMapping("/addPhoto")
    public R<Boolean> addTag(@Valid @RequestBody AddPhotoRO ro) {

        return ResultUtil.success(photoService.addPhoto(ro));
    }
}
